import type { App } from "vue"
import VxeUIPluginRenderElement from "@vxe-ui/plugin-render-element"
import VxeUI from "vxe-pc-ui"
import VxeUITable from "vxe-table"
import { BSDataTypeEnum } from "@/common/constants/other-keys"
import { getRecordBaseValue } from "@/common/utils/parseParamValue"
import { parseParmeValue } from "@@/utils/parseParamValue";

VxeUI.use(VxeUIPluginRenderElement)

// 全局默认参数
VxeUI.setConfig({
  /** 全局尺寸 */
  size: "medium",
  /** 全局 zIndex 起始值，如果项目的的 z-index 样式值过大时就需要跟随设置更大，避免被遮挡 */
  zIndex: 9999,
  /** 版本号，对于某些带数据缓存的功能有用到，上升版本号可以用于重置数据 */
  version: 0,
  table: {
    showHeader: true,
    showOverflow: "tooltip",
    showHeaderOverflow: "tooltip",
    autoResize: true,
    border: "inner",
    emptyText: "暂无数据",
    rowConfig: {
      isHover: true,
      isCurrent: true,
      keyField: "_VXE_ID"
    },
    columnConfig: {
      resizable: false
    },
    align: "center",
    headerAlign: "center"
  },
  pager: {
    perfect: false,
    pageSize: 10,
    pagerCount: 7,
    pageSizes: [10, 20, 50],
    layouts: ["Total", "PrevJump", "PrevPage", "Number", "NextPage", "NextJump", "Sizes", "FullJump"]
  },
  modal: {
    minWidth: 500,
    minHeight: 400,
    lockView: true,
    mask: true,
    dblclickZoom: false,
    showTitleOverflow: true,
    transfer: true,
    draggable: false
  }
})

VxeUI.formats.add('formatValue', {
  cellFormatMethod(item) {
    return item.cellValue && parseParmeValue(item.row);
  }
})

VxeUI.formats.add('formatType', {
  cellFormatMethod ({ cellValue }) {
    return cellValue
    ? cellValue === BSDataTypeEnum.Base
      ? "基本类型"
      : cellValue === BSDataTypeEnum.Enum
      ? "枚举"
      : "类"
    : "";
  }
})

VxeUI.formats.add('formatArrayValue', {
  cellFormatMethod (item) {
    return item.cellValue && getRecordBaseValue(item.row);
  }
})

export function installVxeTable(app: App) {
  // Vxe Table 组件完整引入
  app.use(VxeUI)
  app.use(VxeUITable)
}
